package com.shujia;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
//集群
public class RedisCluster {
    public static void main(String[] args) {
        //如何通过javaAPI连接集群
        //创建JedisCluster的对象
        //需要先将节点封装成set集合
        //每一个节点封装到HostAndPort对象
        HashSet<HostAndPort> hostAndPorts = new HashSet<>();
        hostAndPorts.add(new HostAndPort("192.168.11.100",7000));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7001));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7002));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7003));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7004));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7005));
        hostAndPorts.add(new HostAndPort("192.168.11.100",7006));
        JedisCluster cluster = new JedisCluster(hostAndPorts);


        cluster.set("name","xiaohu");
        cluster.set("age","18");
        cluster.get("name");
        //如果两个键不在一个节点中存储，不能一起删除
        cluster.del("name","age");
        cluster.close();

    }
}
